package cn.hongwei.mall.search.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author Great
 * @email 1224028994@qq.com
 * 对应es中的数据对象，也是搜索结果对应的页面对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "goods"/*,shards = 3,replicas = 2*/) //shards 分片 分布式存储 3个分片分别存储不同的数据 replicas 副本，每个分片的拷贝，防止分片宕机
public class Goods implements Serializable {

    //商品列表所需字段
    @Id
    private Long skuId;
    @Field(type = FieldType.Keyword,index = false) //Keyword 不分词
    private String defaultImage;
    @Field(type = FieldType.Text,analyzer ="ik_max_word" )
    private String title;
    @Field(type = FieldType.Keyword,index = false)
    private String subTitle;
    @Field(type = FieldType.Double)
    private Double price;//不需要计算价格

    //排序过滤
    @Field(type = FieldType.Long)
    private Long sales;
    @Field(type = FieldType.Date)
    private Date createTime;//新品
    @Field(type = FieldType.Boolean)
    private Boolean store;//是否有货

    //品牌聚合所需字段
    @Field(type = FieldType.Long)
    private Long brandId;
    @Field(type = FieldType.Keyword)
    private String brandName;
    @Field(type = FieldType.Keyword)
    private String logo;

    //分类的聚合
    @Field(type = FieldType.Long)
    private Long categoryId;
    @Field(type = FieldType.Keyword)
    private String categoryName;

    //规格参数聚合
    @Field(type = FieldType.Nested)
    private List<SearchAttrValueVo> searchAttrs;
}
